//
//  main.m
//  08-Foundation-NSValue
//
//  Created by Jason on 15/10/7.
//  Copyright © 2015年 Jason. All rights reserved.
//

/*
 NSValue可以包装任何类型数据  主要是用来包装结构体
 NSNumber是继承自NSValue 用来更加方便的包装基本数据类型
 */
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        int age = 10;
        [NSValue valueWithBytes:&age objCType:@encode(int)];
        
        
        
        /*
        struct Student {
          
            int age;
        };
        
        struct Student stu = {20};
         
         [NSValue valueWithBytes:&stu objCType:@encode(struct Student)];
        */
        
        typedef struct {
            int age;
        } Student;
        
        Student stu = {20};
        
        [NSValue valueWithBytes:&stu objCType:@encode(Student)];
        
        
        NSValue *value = [NSValue valueWithPoint:CGPointMake(20, 20)];
        [value pointValue];
        
        /*
        
         这种适用于自定义结构体
         
        // void * 相当于万能指针
        
        CGPoint p = CGPointMake(20, 20);
        
        // 将结构体p包装成一个NSValue对象
        NSValue *value = [NSValue valueWithBytes:&p objCType:@encode(CGPoint)];
        
        NSArray *array = @[value];
        
        NSValue *value2 = array[0];
        
        CGPoint p2;
        [value2 getValue:&p2];
        NSLog(@"p2=%@",NSStringFromPoint(p2));
        
        */
        
    }
    return 0;
}
